package com.baizhi.controller;

import com.baizhi.feign.VideoFeign;
import com.baizhi.po.VideoES;
import com.baizhi.repository.VideoRepository;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cloud.context.config.annotation.RefreshScope;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RefreshScope
@RestController
@RequestMapping("/search")
public class SearhController {

    @Autowired
    private VideoFeign videoFeign;
    @Autowired
    private VideoRepository videoRepository;

    /**
     * 视频搜索
     */
    @GetMapping("/videos")
    public void videos(@RequestParam("q") String q,
                       @RequestParam(value = "page", required = false, defaultValue = "1") Integer page,
                       @RequestParam(value = "per_page", required = false, defaultValue = "1") Integer per_page) {


    }


    /**
     * 用来将视频数据存储至ES，
     * 调用视频服务，查询所有视频数据，将视频数据整合成VideoES,获取数据后，在es这边将数据添加
     */
    @GetMapping("/videos/save")
    public void saveVideo() {
        List<VideoES> videoES = videoFeign.queryAllVideos();
        videoRepository.saveAll(videoES);
    }
}
